"""
通过js逆向的方式采集动态数据：人民邮电出版社热门图书信息
url = 'https://www.ptpress.com.cn/hotBook/getHotBookList?parentTagId=75424c57-6dd7-4d1f-b6b9-8e95773c0593&rows=18&page=1'
"""
import requests
import json
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
}
for i in range(1, 21):
    url = f'https://www.ptpress.com.cn/hotBook/getHotBookList?parentTagId=75424c57-6dd7-4d1f-b6b9-8e95773c0593&rows=20&page={i}'

    res = requests.get(url, headers=headers)
    print(res.text)

    json_data = json.loads(res.text)
    total = json_data['data']['total']
    rows = json_data['data']['rows']
    for row in rows:
        print(row['bookName'], row['price'], row['bookDiscount'], row['picPath'])